#!/usr/bin/perl -wT
use CGI qw(:standard);
use lib '.';
use users;
use strict;
#print header;
#print start_html('User Administration2');
my %FORM;
foreach my $field (param()) 
{
    $FORM{$field} = param($field);
	next if $field eq "Update records";
	my ($type,$user)=split /_/ , $field;
	my $ulevelstr;
	my $ulevel;
	my $uactivestr;
	my $uactive;
#	print p("field=".$field." value=".$FORM{$field});
#	warn "field=".$field." value=".$FORM{$field}." type=".$type." user=".$user;
	my ($cuser,$epass,$email,$level,$active,$gname) = checkuser($user);
#	warn "after check_user ".$cuser." ".$epass." ".$email." ".$level." ".$active." ".$gname;
	if ($type eq "list")
	{
		$ulevelstr=$FORM{$field};
		if ($ulevelstr eq "a User") { $ulevel=10 };
		if ($ulevelstr eq "a Super User") { $ulevel=5 };
		if ($ulevelstr eq "an Administrator") { $ulevel=0 };
		if ($cuser ne "") { update_user($cuser,$epass,$email,$ulevel,0,$gname);}
	}
	else
	{
		if ($type eq "check")
		{
#			warn "before update_user check ".$cuser." ".$epass." ".$email." ".$level." 1 ".$gname;
			if ($cuser ne "") {update_user($cuser,$epass,$email,$level,1,$gname);}
		}
	}
#	print Dumper(%FORM);
	
}
#print end_html;
print redirect(-location=>"admin.pl");
